home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / doc / SetVar.3 < prev    next >
Text File  |  1993-01-31  |  6KB  |  157 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/SetVar.3,v 1.10 93/01/31 15:35:39 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .so man.macros
  13. .HS Tcl_SetVar tcl
  14. .BS
  15. .VS
  16. .SH NAME
  17. Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
  18. .SH SYNOPSIS
  19. .nf
  20. \fB#include <tcl.h>\fR
  21. .sp
  22. char *
  23. \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
  24. .sp
  25. char *
  26. \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
  27. .sp
  28. char *
  29. \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
  30. .sp
  31. char *
  32. \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
  33. .sp
  34. int
  35. \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
  36. .sp
  37. int
  38. \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
  39. .SH ARGUMENTS
  40. .AS Tcl_Interp *newValue
  41. .AP Tcl_Interp *interp in
  42. Interpreter containing variable.
  43. .AP char *varName in
  44. Name of variable.  May refer to a scalar variable or an element of
  45. an array variable.
  46. .AP char *newValue in
  47. New value for variable.
  48. .AP int flags in
  49. OR-ed combination of bits providing additional information for
  50. operation. See below for valid values.
  51. .AP char *name1 in
  52. Name of scalar variable, or name of array variable if \fIname2\fR
  53. is non-NULL.
  54. .AP char *name2 in
  55. If non-NULL, gives name of element within array and \fIname1\fR
  56. must refer to an array variable.
  57. .BE
  58.  
  59. .SH DESCRIPTION
  60. .PP
  61. These procedures may be used to create, modify, read, and delete
  62. Tcl variables from C code.
  63. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR will create a new variable
  64. or modify an existing one.
  65. Both of these procedures set the given variable to the value
  66. given by \fInewValue\fR, and they return a pointer to a
  67. copy of the variable's new value, which is stored in Tcl's
  68. variable structure.
  69. Tcl keeps a private copy of the variable's value, so the caller
  70. may change \fInewValue\fR after these procedures return without
  71. affecting the value of the variable.
  72. If an error occurs in setting the variable (e.g. an array
  73. variable is referenced without giving an index into the array),
  74. then NULL is returned.
  75. .PP
  76. The name of the variable may be specified in either of two ways.
  77. If \fBTcl_SetVar\fR is called, the variable name is given as
  78. a single string, \fIvarName\fR.
  79. If \fIvarName\fR contains an open parenthesis and ends with a
  80. close parenthesis, then the value between the parentheses is
  81. treated as an index (which can have any string value) and
  82. the characters before the first open
  83. parenthesis are treated as the name of an array variable.
  84. If \fIvarName\fR doesn't have parentheses as described above, then
  85. the entire string is treated as the name of a scalar variable.
  86. If \fBTcl_SetVar2\fR is called, then the array name and index
  87. have been separated by the caller into two separate strings,
  88. \fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
  89. zero it means that a scalar variable is being referenced.
  90. .PP
  91. The \fIflags\fR argument may be used to specify any of several
  92. options to the procedures.
  93. It consists of an OR-ed combination of any of the following
  94. bits:
  95. .IP TCL_GLOBAL_ONLY
  96. Under normal circumstances the procedures look up variables
  97. at the current level of procedure call for \fIinterp\fR, or
  98. at global level if there is no call active.
  99. However, if this bit is set in \fIflags\fR then the variable
  100. is looked up at global level even if there is a procedure
  101. call active.
  102. .IP TCL_LEAVE_ERR_MSG
  103. If an error is returned and this bit is set in \fIflags\fR, then
  104. an error message will be left in \fI\%interp->result\fR.  If this
  105. flag bit isn't set then no error message is left (\fI\%interp->result\fR
  106. will not be modified).
  107. .IP TCL_APPEND_VALUE
  108. If this bit is set then \fInewValue\fR is appended to the current
  109. value, instead of replacing it.
  110. If the variable is currently undefined, then this bit is ignored.
  111. .IP TCL_LIST_ELEMENT
  112. If this bit is set, then \fInewValue\fR is converted to a valid
  113. Tcl list element before setting (or appending to) the variable.
  114. If the list element is being appended to an non-empty value, then
  115. a space character is appended before the new list element to
  116. separate it from previous elements.
  117. .IP TCL_NO_SPACE
  118. If this bit is set, it prevents the output of a separating space
  119. character in TCL_LIST_ELEMENT appends.
  120. This bit has no effect if the TCL_LIST_ELEMENT bit isn't set.
  121. .PP
  122. \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR return the current value
  123. of a variable.
  124. The arguments to these procedures are treated in the same way
  125. as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
  126. Under normal circumstances, the return value is a pointer
  127. to the variable's value (which is stored in Tcl's variable
  128. structure and will not change before the next call to \fBTcl_SetVar\fR
  129. or \fBTcl_SetVar2\fR).
  130. The only bits of \fIflags\fR that are used are TCL_GLOBAL_ONLY
  131. and TCL_LEAVE_ERR_MSG, both of
  132. which have
  133. the same meaning as for \fBTcl_SetVar\fR.
  134. If an error occurs in reading the variable (e.g. the variable
  135. doesn't exist or an array element is specified for a scalar
  136. variable), then NULL is returned.
  137. .PP
  138. \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
  139. a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
  140. for the variable will return an error.
  141. The arguments to these procedures are treated in the same way
  142. as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
  143. If the variable is successfully removed then 0 is returned.
  144. If the variable cannot be removed because it doesn't exist
  145. or because a trace is active for it, then -1 is returned.
  146. If an array element is specified, the given element is removed
  147. but the array remains.
  148. If an array name is specified without an index, then the entire
  149. array is removed.
  150.  
  151. .SH "SEE ALSO"
  152. Tcl_TraceVar
  153.  
  154. .SH KEYWORDS
  155. array, interpreter, scalar, set, unset, variable
  156. .VE
  157.